<%= turbo_frame_tag :dialog_modal do %>
  <%= form_for @address, url: spree.admin_order_billing_address_path(@order), data: {controller: 'auto-submit', form_target: 'form', turbo_frame: :_top}, method: :post do |f| %>
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel"><%= Spree.t(:billing_address) %></h5>
        <button type="button" class="btn-close" data-dismiss="modal" aria-label="<%= Spree.t(:close) %>" ></button>
      </div>
      <div class="modal-body d-flex flex-col gap-3" data-controller="order-billing-address">
        <div>
          <% if @order.shipping_address.present? %>
            <%= label_tag nil, class: 'form-control custom-radio' do %>
              <%= radio_button_tag :billing_address_type, :same_as_shipping, true, class: 'custom-control-input', data: {action: 'order-billing-address#hideForms'} %>
              <span class="custom-control-label ml-4"><%= Spree.t(:same_as_shipping_address) %></span>
            <% end %>
          <% end %>
          <%= label_tag nil, class: 'form-control custom-radio' do %>
            <%= radio_button_tag :billing_address_type, :new, @order.shipping_address.nil? || params[:selected_form] == 'new', class: 'custom-control-input', data: {action: 'order-billing-address#showForm', order_billing_address_form_name_param: "new_address"} %>
            <span class="custom-control-label ml-4"><%= Spree.t(:add_new_address) %></span>
          <% end %>
          <% if @order.user.present? && @order.user.addresses.many? %>
            <%= label_tag nil, class: 'form-control custom-radio' do %>
              <%= radio_button_tag :billing_address_type, :existing, false, class: 'custom-control-input', data: {action: 'order-billing-address#showForm', order_billing_address_form_name_param: "existing_address"} %>
              <span class="custom-control-label ml-4"><%= Spree.t(:select_existing_address) %></span>
            <% end %>
          <% end %>
        </div>
        <%= render 'form', address: @address, f: f %>
      </div>
      <div class="modal-footer d-flex justify-content-between">
        <button type="button" class="btn btn-light" data-dismiss="modal"><%= Spree.t('actions.discard') %></button>
        <%= turbo_save_button_tag Spree.t('actions.save') %>
      </div>
    </div>
  <% end %>
<% end %>
